package com.yndsoft.jc.activity;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.LayoutRes;
import android.view.View;
import android.view.ViewGroup;

import com.yndsoft.jc.core.ActivitiesManager;
import com.yndsoft.jc.ui.memberpage.Session;
import com.yndsoft.jc.ui.net.HttpUtil;
import com.yndsoft.jc.utils.AppProcessStateUtil;
import com.yndsoft.jc.utils.ConstantValues;
import com.yndsoft.jc.utils.StatusBarCompat;

import butterknife.ButterKnife;

/**
 * Created by Administrator on 2016-08-23.
 */
public abstract class BaseActivity extends Activity {
    protected Context mContext;
    protected HttpUtil mHttpUtil;
    protected Session mSession;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        StatusBarCompat.translucentStatusBar2(this);
    }

    @Override
    public void setContentView(@LayoutRes int layoutResID) {
        super.setContentView(layoutResID);
        init();
    }

    private void init() {
        mContext = this;
        // onCreate时，对activity入栈操作
        ActivitiesManager.getInstance().pushActivity(this);
        ButterKnife.bind(this);
        mSession = Session.get(getApplicationContext());
        mHttpUtil = HttpUtil.getInstance();
    }

    @Override
    public void setContentView(View view) {
        super.setContentView(view);
        init();
    }

    @Override
    public void setContentView(View view, ViewGroup.LayoutParams params) {
        super.setContentView(view, params);
        init();
    }

    public <T extends View> T findViews(int viewID) {
        return (T) findViewById(viewID);
    }


    @Override
    protected void onStart() {
        super.onStart();

    }

    @Override
    protected void onResume() {
        super.onResume();
        if (!ConstantValues.isActive) {
            //app 从后台唤醒，进入前台
            ConstantValues.isActive = true;
            if (!ConstantValues.APP_STATUS.equals(ConstantValues.AppStatus.REBIRTH.getValue())) {
                ConstantValues.APP_STATUS = ConstantValues.AppStatus.AWAKENED.getValue();
            }
        }

    }

    @Override
    protected void onPause() {
        super.onPause();

    }

    @Override
    protected void onStop() {
        super.onStop();
        if (!AppProcessStateUtil.isAppOnForeground(this)) {
            //app 进入后台
            ConstantValues.isActive = false;
            ConstantValues.APP_STATUS = ConstantValues.AppStatus.FALLASLEEP.getValue();
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        // onDestory时，出栈操作
        ActivitiesManager.getInstance().popActivity(this);
        ButterKnife.unbind(this);
    }


}
